package com.dg.controller;

import com.dg.common.PageQuery;
import com.dg.common.PageResult;
import com.dg.common.ServerResponse;
import com.dg.dto.AclDto;
import com.dg.param.AclParam;
import com.dg.pojo.Acl;
import com.dg.pojo.AclModule;
import com.dg.service.AclService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mrq
 */
@RestController
@RequestMapping("/acl/")
public class AclController {

    @Autowired
    private AclService aclService;

    @RequestMapping("list")
    public ServerResponse<PageResult<AclDto>> list(Integer aclModuleId, PageQuery pageQuery){
        return ServerResponse.createBySuccess(aclService.list(aclModuleId, pageQuery));
    }

    @RequestMapping("save")
    public ServerResponse<List<AclModule>> save(AclParam param){
        aclService.save(param);
        return ServerResponse.createBySuccess();
    }

    @RequestMapping("update")
    public ServerResponse update(AclParam param){
        aclService.update(param);
        return ServerResponse.createBySuccess();
    }

    @RequestMapping("saveOrUpdate")
    public ServerResponse saveOrUpdate(AclParam param){
        aclService.saveOrUpdate(param);
        return ServerResponse.createBySuccess();
    }

    @RequestMapping("delete")
    public ServerResponse delete(Integer id){
        aclService.delete(id);
        return ServerResponse.createBySuccess();
    }

}
